<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted Access');
// load tooltip behavior
JHtml::_('behavior.tooltip');
$editor =& JFactory::getEditor();
?>
<form action="<?php echo JRoute::_('index.php?option=com_shop'); ?>"   method="post" name="adminForm" enctype="multipart/form-data">
<div class="width-60 fltlft">
		<fieldset class="adminform">
			<legend>Nhập thông tin công ty</legend>
			<ul class="adminformlist">
				<li><label id="vtitle" for="" class="required" title="">Tên Công Ty - Việt<span class="star">&nbsp;*</span></label>
                <input type="text" name="vtitle" id="vtitle" value="<?php echo $this->item->vtitle; ?>" class="inputbox required" size="50" aria-required="true" required="required"></li>
                <li><label id="etitle" for="" class="" title="">Tên Công Ty - Anh</label>
                <input type="text" name="etitle" id="etitle" value="<?php echo $this->item->etitle; ?>" class="inputbox" size="50"></li>
                <li><label id="alias" for="alias" class="required" title="">Alias</label>
                <input type="text" name="alias" id="alias" value="<?php echo $this->item->alias; ?>" class="inputbox" size="50"></li>
                <li><label id="address" for="" class="required" title="">Địa chỉ<span class="star">&nbsp;*</span></label>
                <input type="text" name="address" id="address" value="<?php echo $this->item->address; ?>" class="inputbox required" size="50" aria-required="true" required="required"></li>
                <li><label id="subadd" for="" title="">Chi nhánh</label>
                <textarea name="subadd" id="subadd" rows="4"><?php echo $this->item->subadd; ?></textarea></li>
                <li><label id="email" for="" class="required" title="">Email<span class="star">&nbsp;*</span></label>
                <input type="text" name="email" id="email" value="<?php echo $this->item->email; ?>" class="inputbox required" size="50" aria-required="true" required="required"></li>
                <li><label id="phone" for="" class="required" title="">Điện thoại<span class="star">&nbsp;*</span></label>
                <input type="text" name="phone" id="phone" value="<?php echo $this->item->phone; ?>" class="inputbox required" size="50" aria-required="true" required="required"></li>
                <li><label id="fax" for="" class="required" title="">Fax</label>
                <input type="text" name="fax" id="fax" value="<?php echo $this->item->fax; ?>" class="inputbox" size="50"></li>
                <li><label id="yahoo" for="" class="required" title="">Yahoo</label>
                <input type="text" name="yahoo" id="yahoo" value="<?php echo $this->item->yahoo; ?>" class="inputbox" size="50"></li>
                <li><label id="skyper" for="" class="required" title="">Skyper</label>
                <input type="text" name="skyper" id="skyper" value="<?php echo $this->item->skyper; ?>" class="inputbox" size="50"></li>
                <li>
                <label id="address_id" for="">Địa chỉ</label>
                <select name="address_id" id="address_id">
                	<?php echo JHtml::_('select.options', $this->getAddresses(), 'value', 'text', $this->item->address_id, true);?>
                </select>
                </li>
                <li><label id="website" for="" class="required" title="">Website</label>
                <input type="text" name="website" id="website" value="<?php echo $this->item->website; ?>" class="inputbox" size="50"></li>
                <li>
                <label id="state" for="state">Bật</label>
			<select name="state" class="inputbox">
				<option value=""><?php echo JText::_('JOPTION_SELECT_PUBLISHED');?></option>
				<?php echo JHtml::_('select.options', JHtml::_('jgrid.publishedOptions'), 'value', 'text', $this->item->state, true);?>
			</select>
                </li>
                <li><label id="catid" for="catid" title="">Chọn danh mục</label>
                <select name="catid" class="inputbox">
            	<option value=""><?php echo  JText::_('JGLOBAL_ROOT_PARENT'); ?></option>
				<?php echo JHtml::_('select.options', $this->getOptions(), 'value', 'text', $this->item->catid, true);?>
				</select></li>
                <li><label id="upload_file" for="upload_file">Logo doanh nghiệp</label>
                 <input type="file" name="upload_file" />
                </li>
			</ul>
            <div class="clr"></div>
            <?php if($this->item->logo_img != ''): ?>
            <img src="<?php echo JURI::root().'images/logo_image/thumb/'.$this->item->logo_img; ?>" width="50" height="50" style="margin-left:150px;" />
            <?php endif; ?>
            <div class="clr"></div>
             <label>Giới thiệu về doanh nghiệp</label>
            <div class="clr"></div>
            <?php 
			echo $editor->display('introtext', $this->item->introtext , '100%', '300', '60', '20', true);
			
			?>
            <div class="clr"></div>
             <label>Mô tả chi tiết về doanh nghiệp</label>
            <div class="clr"></div>
            <?php 
			echo $editor->display('fulltext', $this->item->fulltext , '100%', '400', '60', '20', true);
			?>
            
            
		</fieldset>
</div>
<?php
$id = ($this->item->id == NULL)?0:$this->item->id;
$db =& JFactory::getDBO();
$query = $db->getQuery(true);
$query->select("*");
$query->from('#__shop_attach');
$query->where('product_id = '.$id);
$db->setQuery((string)$query);
$attach = $db->loadObjectList();
$pathimage = JURI::root().'images/image_product/thumb/';
?>
<div class="width-40 fltrt">
<div class="title-info">
Cập nhật ảnh doanh nghiệp
</div>
<div id="upload">Chọn ảnh</div>
<span id="status_process" ></span>
<div id="responser">
  <ul>
  	<?php foreach($attach as $row):?>
<li id="<?php echo $row->id; ?>">
    <img src="<?php echo $pathimage.$row->filename; ?>" width="50" height="50" /><br />
    <input type="radio" <?php if($this->item->image == $row->filename): ?> checked="checked" <?php endif; ?> name="mainimage" value="<?php echo $row->filename; ?>" class="mainimage"/>
    <label>Ảnh chính</label><br />
    <input type="hidden" name="imageattach[]" value="<?php echo $row->id; ?>" />
    <a href="javascript:;" onclick="removefile(<?php echo $row->id; ?>);">Xóa ảnh</a>
</li>
    <?php endforeach;?>
  </ul>
</div>
</div>
<input type="hidden" name="task" value="" />
<input type="hidden" name="id" value="<?php echo $this->item->id; ?>" />
<input type="hidden" name="ordering" value="<?php echo $this->item->ordering ?>" />
<?php echo JHtml::_('form.token'); ?>
</form>
<script>
Joomla.submitbutton = function(task)
{
	if (task == '')
	{
		return false;
	}
	else
	{
		var action = task.split('.');
		if (action[1] != 'cancel' && action[1] != 'close')
		{
			var $frm = document.adminForm;
			if($frm.vtitle.value == '')
			{
				alert('Nhập tên công ty');
				$frm.vtitle.focus();
				return false;
			}
			else if($frm.catid.value == ''){
				alert('Chọn danh mục cho sản phẩm');
				$frm.catid.focus();
				return false;
			}else{
				Joomla.submitform(task);
				return true;
			}
		}
		else
			{
				Joomla.submitform(task);
				return true;
			}
	}
}
</script>
<style>
.star{ color:#FF0000;}
#upload{
	padding:15px;
	font-weight:bold; font-size:1.3em;
	font-family:Arial, Helvetica, sans-serif;
	text-align:center;
	background:#f2f2f2;
	color:#3366cc;
	border:1px solid #ccc;
	width:150px;
	cursor:pointer !important;
	-moz-border-radius:5px; -webkit-border-radius:5px;
}
.title-info{padding: 5px;background: #FDA;border: 1px solid #FDA;border-radius: 5px 5px 0px 0px;margin-bottom: 5px;}
#responser{}
#responser ul{}
#responser ul li{ list-style:none; width:90px; height:90px; float:left; margin:2px;}
</style>
<script src="<?php echo JURI::base().'components/com_shop/images/'; ?>jquerymin.js" type="text/javascript"></script>
<script>jQuery.noConflict();</script>
<script src="<?php echo JURI::base().'components/com_shop/images/'; ?>ajaxupload.js" type="text/javascript"></script>
<script type="text/javascript">
	jQuery(function(){
		var btnUpload=jQuery('#upload');
		var status=jQuery('#status_process');
		new AjaxUpload(btnUpload, {
			action: '<?php echo JURI::base()."index.php?option=com_shop&view=process&type=upload&id=".$this->item->id; ?>',
			name: 'uploadfile',
			onSubmit: function(file, ext){
				 if (! (ext && /^(jpg|png|jpeg|gif|)$/.test(ext))){ 
                    // extension is not allowed 
					status.text('Only JPG, PNG or GIF files are allowed');
					alert('Chỉ được upload file ảnh dạng JPG, PNG or GIF');
					return false;
				}
			
				status.text('Uploading...');
			},
			onComplete: function(file, response){
				//On completion clear the status
				status.text('');
				$arr = response.split('==');;
				if($arr[0] == 'ok'){
				jQuery('#responser ul').append($arr[3]);
				}else{ alert('Xảy ra lỗi khi upload ảnh cho sản phẩm');}
			}
		});
		
	});
function removefile(id){
		jQuery.ajax({
	   type: "POST",
	   url: "<?php echo JURI::base()."index.php?option=com_shop&view=process&type=deletefile&id="; ?>"+id,
	   success: function(msg){
		// alert( "Data Saved: " + msg );
		jQuery('#'+msg).remove();
	   }
	 });
}
</script> 